/**
 * 
 */
package cc.rico.api;

import java.io.IOException;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.junit.Test;

/**
 * zookeeper api demo
 * @author rico 2016年8月20日
 * 
 */
public class ZKApiTest extends BaseZK {
	private static final String ZK_HOST = "127.0.0.1:2181";
	
	@Test
	public void testConnectToZk() {
		ZooKeeper zk = null;
		try {
			zk = new ZooKeeper(ZK_HOST, DEFAULT_SESSION_TIMEOUT, new Watcher() {
				@Override
				public void process(WatchedEvent event) {
					if(event.getState() == KeeperState.SyncConnected) {
						logger.info("Connect to zk successfully...");
					}
				}
			});
			
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if(zk != null) {
					zk.close();
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
}
